Code Challenge Season3

The number for which the remainder is 1 (Lv. 1)
https://school.programmers.co.kr/learn/courses/30/lessons/87389
#include <iostream>
using namespace std;
int solution(int n){
for(int i=0; ; ++i){
if(n%i==1) return i;
}
}
int main(void){
int n1=10, n2=12;
int result1, result2;
result1=solution(n1);
result2=solution(n2);
cout<<"Result1: "<<result1<<endl;
cout<<"Result2: "<<result2<<endl;
return 0;
}
Add missing numbers (Lv. 1)
https://school.programmers.co.kr/learn/courses/30/lessons/86051
#include <iostream>
#include <vector>
int solution(std::vector<int> numbers){
int answer=45;
for(int num: numbers) answer-=num;
return answer;
}
int main(void){
std::vector<int> numbers1={1, 2, 3, 4, 6, 7, 8, 0};
std::vector<int> numbers2={5, 8, 4, 0, 6, 7, 9};
std::cout<<"result1: "<<solution(numbers1)<<std::endl;
std::cout<<"result2: "<<solution(numbers2)<<std::endl;
return 0;
}
split n^2 array (Lv. 2)
https://school.programmers.co.kr/learn/courses/30/lessons/87390
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
vector<int> solution(int n, ll left, ll right){
vector<int> array(n*n, 0);
vector<int> answer;
int point=0, tmp;
for(int i=0; i<n*n; ++i){
array[i]=std::max(i%n, i/n)+1;
}
for(int i=left; i<right+1; ++i){
answer.push_back(array[i]);
}
return answer;
}
void print_vec(vector<int> result){
if(!result.size()) return;
cout<<"\n[";
for(int i=0; i<result.size()-1; ++i){
cout<<result[i]<<", ";
}
cout<<result[result.size()-1]<<']'<<endl;
}
int main(void){
int n1=3, n2=4;
ll left1=2, left2=7, right1=5, right2=14;
vector<int> result1=solution(n1, left1, right1);
vector<int> result2=solution(n2, left2, right2);
print_vec(result1);
print_vec(result2);
return 0;
}
Moving Ball simulation (Lv. 3)
https://school.programmers.co.kr/learn/courses/30/lessons/87391
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
void move(const int& n, const int& m, int& x, int &y, const int& direct){
int xx=x, yy=y;
switch(direct){
case 0:
yy--;
break;
case 1:
yy++;
break;
case 2:
xx--;
break;
case 3:
xx++;
}
if(xx<0 || xx>n-1 || yy<0 || yy>m-1) return;
else{
x=xx; y=yy;
return;
}
}
ll solution(int n, int m, int x, int y, vector<vector<int>> queries){
ll answer=0;
// initial point [tmp_x, tmp_y]
for(int tmp_x=0; tmp_x<n; ++tmp_x){
for(int tmp_y=0; tmp_y<m; ++tmp_y){
int xx=tmp_x, yy=tmp_y;
// with queries move
for(vector<int> query: queries){
for(int i=0; i<query[1]; ++i){
move(n, m, xx, yy, query[0]);
}
}
// after queries
if(xx==x && yy==y) ++answer;;
}
}
return answer;
}
int main(void){
int n1=2, n2=2, m1=2, m2=5, x1=0, x2=0, y1=0, y2=1;
vector<vector<int>> queries1={
{2, 1},
{0, 1},
{1, 1},
{0, 1},
{2, 1}
};
vector<vector<int>> queries2={
{3, 1},
{2, 2},
{1, 1},
{2, 3},
{0, 1},
{2, 1}
};
cout<<"result1: "<<solution(n1, m1, x1, y1, queries1)<<endl;
cout<<"result2: "<<solution(n2, m2, x2, y2, queries2)<<endl;
return 0;
}
Transport Gold & Silver (Lv. 3)
https://school.programmers.co.kr/learn/courses/30/lessons/86053

not solved yet
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll solution(int a, int b, vector<int> g, vector<int> s, vector<int> w, vector<int> t){
ll answer=-1;
return answer;
}
int main(void){
int a1=10, b1=10, a2=90, b2=500;
vector<int> g1={100};
vector<int> g2={70, 70, 0};
vector<int> s1={100};
vector<int> s2={0, 0, 500};
vector<int> w1={7};
vector<int> w2={100, 100, 2};
vector<int> t1={10};
vector<int> t2={4, 8, 1};
cout<<"Result1: "<<solution(a1, b1, g1, s1, w1, t1)<<endl;
cout<<"Result2: "<<solution(a2, b2, g2, s2, w2, t2)<<endl;
return 0;
}